package sosopkpk;

import java.util.Scanner;

public class J16Ch05Calculator {

	public static void main(String[] args) {
		// 클래스 선언
		Scanner sc = new Scanner(System.in);
		String msg = "두 정수와 연산자를 입력하시오>> ";

		// new 연산자를 이용한 객체 생성은 최대한 천천히 실행할 것!
		// 업캐스팅을 이용해서 참조변수 cal 선언
		J16Cal cal = null;
		J16CalService cs = new J16CalService();

		// 입력
		System.out.print(msg);
		int a = sc.nextInt();
		int b = sc.nextInt();
		String c = sc.next();
		msg = "연산자만 입력가능!!";
		sc.close();
		
		switch (c) {
		case "+":
			cal = new J16Add();
			cal.setValue(a, b);
			cs.calculate(cal,c);
			break;
		case "-":
			cal = new J16Sub();
			cal.setValue(a, b);
			cs.calculate(cal,c);
			break;
		case "x":
			cal = new J16Mul();
			cal.setValue(a, b);
			cs.calculate(cal,c);
			break;
		case "/":
			cal = new J16Div();
			cal.setValue(a, b);
			cs.calculate(cal,c);
			break;
		default:
			System.out.println(msg);
		}

	} // main

} // class

class J16Cal {
	private int x;
	private int y;

	void setValue(int x, int y) {
		this.x = x;
		this.y = y;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

	@Override
	public String toString() {
		String result = "";
		result += x + "/" + y;
		return result;
	}
}

class J16Add extends J16Cal { }
class J16Sub extends J16Cal { }
class J16Mul extends J16Cal { }
class J16Div extends J16Cal { }

interface J16CalIService {
	void calculate(J16Cal cal, String type);
}

class J16CalService implements J16CalIService {

	@Override
	public void calculate(J16Cal cal, String type) {
		int result = 0;
		switch (type) {
		case "+":
			result = cal.getX() + cal.getY();
			break;
		case "-":
			result = cal.getX() - cal.getY();
			break;
		case "x":
			result = cal.getX() * cal.getY();
			break;
		case "/":
			result = cal.getX() / cal.getY();
			break;
		}
		System.out.println(result);
	}

}
